package logic

import (
	"context"
	"course_srv/models/mysql"

	"course_srv/course"
	"course_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *course.OrderListRequest) (*course.OrderListResponse, error) {

	o := mysql.Order{}
	list, _ := o.List(in.StartTime, in.EndTime, in.OrderSn)

	var slice []*course.OrderList
	for _, order := range list {
		slice = append(slice, &course.OrderList{
			UserId:    int32(order.UserId),
			OrderSn:   order.OrderSn,
			PayType:   int32(order.PayType),
			PayStatus: int32(order.PayStatus),
			Amount:    float32(order.Amount),
		})
	}
	return &course.OrderListResponse{List: slice}, nil
}
